Skip to content

stabilize test by actively check and wait till program is usable by runtime #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tao-stones
Copy link

  • programs added to TestValidator's genesis isn't immediately usable. Runtime needs time to mark the program as "deployed";
  • TestValidator has a hack during startup to wait for fee stabilizes.
  • During this wait period, programs in TestValidator genesis usually will become ready for use; But this isn't always reliable, sometime cause test to fail due to "Program is not deployed":
Waiting for fees to stabilize 1...

thread 'main' panicked at clients/cli/tests/command.rs:278:14:
called `Result::unwrap()` on an `Err` value: Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0: Unsupported program id", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, UnsupportedProgramId)), logs: Some(["Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]", "Program is not deployed", "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: Unsupported program id"]), accounts: None, units_consumed: Some(0), return_data: None, inner_instructions: None, replacement_blockhash: None }) }) }

Solution:

  • Actively check for "Program is not deployed", wait till program becomes usable.

Copy link
Contributor

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to instead just wait for slot 1 on the test validator before executing tests?

@tao-stones
Copy link
Author

Is it possible to instead just wait for slot 1 on the test validator before executing tests?

Yea, thought about that first, that approach might be less code, but don't like too much about replacing one assumption with another. Prefer to directly check if the program that's seeded is indeed ready for use, feel like that's more straightforward and solid for tests.

Also tried to make it bit more readable by checking if sol_token_2022 is ready in new_validator_for_test() function, right after test_validator is started (at Ln 175), by calling a new function wait_until_program_deployed(), that would try to construct a dummy/no-op instruction with it (something like let instruction = Instruction::new_with_bytes(sol_token_2022::id(), &[], vec![]);), then loop/wait till it's ready. But such instruction didn't work (due to error "invalid parameter"). 🤷🏼

Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes themselves look fine to me. Are the delay duration calculated empirically?

Having a wait_until_program_deployed() function would definitely make the code more readable and modular. I think the token program will give an error on an empty instruction data, but such error would also demonstrate that the program is usable, so that might be a more modular approach as well.

@joncinque
Copy link
Contributor

This kind of fix makes it seem like everyone will have to fix their tests, so why not fix this in solana-test-validator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants